﻿@model Vizzio.Models.Cliente

@{
    ViewBag.Title = "Registrar Cliente";
    
}

<h2>Registrar Cliente</h2>


@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formularioPersona" }))
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Cliente</h4>
        <p><font color="blue" face="Verdana" size="2">Todos los campos con * son obligatorios</font></p>
        <hr />
        @Html.ValidationSummary(true)

        @Html.HiddenFor(model => model.SocioID, new { @Value = ViewBag.IDSocioSeleccionado })
       
        <div class="control-group form-group">
            <label class="control-label col-md-2" for="disabledInput"><strong>Nombre de Socio</strong></label>
            <div class="col-md-10">
                <input class="form-control" id="disabledInputEstado" placeholder="@ViewBag.nombreDeSocio" disabled="" type="text">
            </div>
        </div>

        <div class="control-group form-group">
            <label class="control-label col-md-2"><strong>*CI</strong></label>
            <div class="col-md-10 controls">
                @Html.TextBoxFor(model => model.CI, new { @class = "form-control", required = "", data_validation_required_message = "Campo requerido", maxlength = "10", data_validation_maxlength_message = "Muy largo: Ingrese menos de 15 digitos", minlength = "6", data_validation_minlength_message = "Muy corto: Ingrese al menos 6 digitos", data_validation_number_message = "Debe ingresar solo numeros", data_validation_callback_callback = "validar_ci_cliente_repetido" })
                <p class="help-block">Campo requerido. De 6 a 10 Digitos Numericos</p>
            </div>
        </div>

        <div class="control-group form-group">
            <label class="control-label col-md-2"><strong>* Nombre</strong></label>
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Nombre, new { @class = "form-control", required = "", data_validation_required_message = "Campo requerido", maxlength = "20", data_validation_maxlength_message = "Muy largo: Ingrese 20 o menos caracteres", minlength = "2", data_validation_minlength_message = "Muy corto: Ingrese al menos 2 caracteres", data_validation_regex_regex = "([A-ZñÑa-z]+[ ]{0,1})*([A-ZñÑa-z]+$)", data_validation_regex_message = "Solo caracteres Alfabeticos sin espacios al principio ni final. Sin espacios Dobles" })
                <p class="help-block">2 a 20 Digitos Albeticos</p>
            </div>
        </div>

        <div class="control-group form-group">
            <label class="control-label col-md-2"><strong>* Apellidos</strong></label>
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Apellidos, new { @class = "form-control", required = "", data_validation_required_message = "Campo requerido", maxlength = "30", data_validation_maxlength_message = "Muy largo: Ingrese 30 o menos caracteres", minlength = "2", data_validation_minlength_message = "Muy corto: Ingrese al menos 2 caracteres", data_validation_regex_regex = "([A-ZñÑa-z]+[ ]{0,1})([A-ZñÑa-z]+$)", data_validation_regex_message = "Solo caracteres Alfabeticos. Maximo dos Apellidos" })
                <p class="help-block">2 a 30 Digitos Albeticos</p>
            </div>
        </div>

        <div class="control-group form-group">
            <label class="control-label col-md-2"><strong>* Telefono</strong></label>
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Telefono, new { @class = "form-control", required = "", data_validation_required_message = "Campo requerido", maxlength = "10", data_validation_maxlength_message = "Muy largo: Ingrese menos de 10 digitos", minlength = "7", data_validation_minlength_message = "Muy corto: Ingrese al menos 7 digitos", data_validation_number_message = "Debe ingresar solo numeros" })
                <p class="help-block">Campo requerido. De 7 a 10 Digitos Numericos</p>
                @*@Html.ValidationMessageFor(model => model.Telefono)*@
            </div>
        </div>

        <div class="control-group form-group">
            <label class="control-label col-md-2"><strong>* Celular</strong></label>
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Celular, new { @class = "form-control", required = "", data_validation_required_message = "Campo requerido", maxlength = "11", data_validation_maxlength_message = "Muy largo: Ingrese menos de 11 digitos", minlength = "8", data_validation_minlength_message = "Muy corto: Ingrese al menos 8 digitos", data_validation_number_message = "Debe ingresar solo numeros" })
                <p class="help-block">Campo requerido. De 8 a 11 Digitos Numericos</p>
                @*@Html.ValidationMessageFor(model => model.Celular)*@
            </div>
        </div>


        <div class="form-group controls">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Registrar" class="btn btn-primary" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Cancelar", "Index", new { id = ViewBag.IDSocioSeleccionado }, new { @class = "btn btn-success"})
</div>

@section Scripts {
    <script>
        $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); });
    </script>


<script>
    function validar_ci_cliente_repetido($el, value, validar_ci) {
        var obj = { CI: value };//Datos enviados
        $.ajax({
            type: "POST",
            url: "http://localhost:6490/Service/WebServiceGetProductos.asmx/NuevoCiClienteDisponible",
            dataType: "json",
            data: JSON.stringify(obj),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                validar_ci({
                    value: value,
                    valid: JSON.parse(data.d),
                    message: "Duplicidad: El CI ingresado ya fue registrado!!"
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus + " Error: " + XMLHttpRequest.responseText);
            }
        });
    }
</script>

    @Scripts.Render("~/bundles/jqueryval")
}
